{
Author:  Prof1983 prof1983@yandex.ru
Created: 01.03.2009
LastMod: 20.03.2009
}
unit AUIclMemo;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Classes, Controls, Forms, Graphics, StdCtrls,
  ABase, ABaseIntf, AUI, AUIcl, AUIclFont, AUIclPopupMenu;

type

  { TAUIMemo }

  TAUIMemo = class(TInterfacedObject, IAUIclMemo, IAUIWidget)
  private
    FControl: TMemo;
    FOnKeyDown: IABasicIntSignal;
    FOnKeyUp: IABasicIntSignal;
    FRequestSize: TAUISize;
    FUI: IAUserInterface;
    procedure MemoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure MemoKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  public // IAUIWidget
    function GetRequestSize: TAUISize;
    procedure SetAllocateSize(Width, Height: Integer);
    procedure SetPosition(ALeft, ATop: Integer);
    procedure SetRequestSize(Width, Height: Integer);
  public // IAUIContainer
    procedure AddWidget(Widget: IAUIWidget);
  protected // IAUIControl
    function GetEnabled: ABoolean;
    function GetHint: AString;
    function GetName: AString;
    function GetText: AString;
    function GetVisible: ABoolean;
    procedure SetEnabled(Value: ABoolean);
    procedure SetHint(const Value: AString);
    procedure SetName(const Value: AString);
    procedure SetText(const Value: AString);
    procedure SetVisible(Value: ABoolean);
  protected // IAUIMemo
    function Get_Tag: Integer;
    procedure Set_Tag(Value: Integer);
    function Get_Left: Integer;
    procedure Set_Left(Value: Integer);
    function Get_Top: Integer;
    procedure Set_Top(Value: Integer);
    function Get_Width: Integer;
    procedure Set_Width(Value: Integer);
    function Get_Height: Integer;
    procedure Set_Height(Value: Integer);
    function Get_Cursor: Integer;
    procedure Set_Cursor(Value: Integer);
    function Get_HelpType: Integer;
    procedure Set_HelpType(Value: Integer);
    function Get_HelpKeyword: AString;
    procedure Set_HelpKeyword(const Value: AString);
    function Get_HelpContext: Integer;
    procedure Set_HelpContext(Value: Integer);
    function Get_TabStop: ABoolean;
    procedure Set_TabStop(Value: ABoolean);
    function Get_Align: Integer;
    procedure Set_Align(Value: Integer);
    function Get_Alignment: Integer;
    procedure Set_Alignment(Value: Integer);
    function Get_BevelInner: Integer;
    procedure Set_BevelInner(Value: Integer);
    function Get_BevelKind: Integer;
    procedure Set_BevelKind(Value: Integer);
    function Get_BevelOuter: Integer;
    procedure Set_BevelOuter(Value: Integer);
    function Get_BiDiMode: Integer;
    procedure Set_BiDiMode(Value: Integer);
    function Get_BorderStyle: Integer;
    procedure Set_BorderStyle(Value: Integer);
    function Get_Color: Integer;
    procedure Set_Color(Value: Integer);
    //function Get_Ctl3D: Integer;
    //procedure Set_Ctl3D(Value: Integer);
    function Get_DragCursor: Integer;
    procedure Set_DragCursor(Value: Integer);
    function Get_DragKind: Integer;
    procedure Set_DragKind(Value: Integer);
    function Get_DragMode: Integer;
    procedure Set_DragMode(Value: Integer);
    function Get_Font: IAUIFont;
    function Get_HideSelection: ABoolean;
    procedure Set_HideSelection(Value: ABoolean);
    function Get_ImeMode: Integer;
    procedure Set_ImeMode(Value: Integer);
    function Get_ImeName: AString;
    procedure Set_ImeName(const Value: AString);
    function Get_LinesCount: integer;
    function Get_Lines(Index: integer): AString;
    procedure Set_Lines(Index: integer; const Value: AString);
    function Get_MaxLength: Integer;
    procedure Set_MaxLength(Value: Integer);
    //function Get_OEMConvert: Integer;
    //procedure Set_OEMConvert(Value: Integer);
    //function Get_ParentBiDiMode: Integer;
    //procedure Set_ParentBiDiMode(Value: Integer);
    //function Get_ParentColor: Integer;
    //procedure Set_ParentColor(Value: Integer);
    //function Get_ParentCtl3D: Integer;
    //procedure Set_ParentCtl3D(Value: Integer);
    //function Get_ParentFont: Integer;
    //procedure Set_ParentFont(Value: Integer);
    //function Get_ParentShowHint: Integer;
    //procedure Set_ParentShowHint(Value: Integer);
    function Get_PopupMenu: IAUIPopupMenu;
    function Get_ReadOnly: ABoolean;
    procedure Set_ReadOnly(Value: ABoolean);
    function Get_ScrollBars: Integer;
    procedure Set_ScrollBars(Value: Integer);
    //function Get_ShowHint: Integer;
    //procedure Set_ShowHint(Value: Integer);
    function Get_TabOrder: Integer;
    procedure Set_TabOrder(Value: Integer);
    function Get_WantReturns: ABoolean;
    procedure Set_WantReturns(Value: ABoolean);
    function Get_WantTabs: ABoolean;
    procedure Set_WantTabs(Value: ABoolean);
    function Get_WordWrap: ABoolean;
    procedure Set_WordWrap(Value: ABoolean);
  public // IAUIMemo
    procedure AddLine(const Text: AString);
    procedure Clear;
    function GetOnKeyDown: IABasicIntSignal;
    function GetOnKeyUp: IABasicIntSignal;
    procedure SetFocus;
  public
    constructor Create(UI: IAUserInterface; Control: TMemo);
    class function New(UI: IAUserInterface): IAUIclMemo;
  end;

implementation

{ TAUIMemo }

procedure TAUIMemo.AddLine(const Text: AString);
begin
  FControl.Lines.Add(Text);
end;

procedure TAUIMemo.AddWidget(Widget: IAUIWidget);
begin
end;

procedure TAUIMemo.Clear;
begin
  FControl.Clear();
end;

constructor TAUIMemo.Create(UI: IAUserInterface; Control: TMemo);
begin
  FControl := Control;
  FUI := UI;
  FUI.RegisterWidgetControl(Self, Control);
end;

function TAUIMemo.GetOnKeyDown: IABasicIntSignal;
begin
  if not(Assigned(FOnKeyDown)) then
  begin
    FOnKeyDown := FUI.Core.NewBasicIntSignal('', '');
    FControl.OnKeyDown := MemoKeyDown;
  end;
  Result := FOnKeyDown;
end;

function TAUIMemo.GetOnKeyUp: IABasicIntSignal;
begin
  if not(Assigned(FOnKeyDown)) then
  begin
    FOnKeyDown := FUI.Core.NewBasicIntSignal('', '');
    FControl.OnKeyUp := MemoKeyUp;
  end;
  Result := FOnKeyDown;
end;

function TAUIMemo.GetRequestSize: TAUISize;
begin
  Result := FRequestSize;
end;

function TAUIMemo.GetName: AString;
begin
  Result := FControl.Name;
end;

procedure TAUIMemo.MemoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if Assigned(FOnKeyDown) then
  begin
    FOnKeyDown.Invoke(0, Key);
  end;
end;

procedure TAUIMemo.MemoKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if Assigned(FOnKeyUp) then
  begin
    FOnKeyUp.Invoke(0, Key);
  end;
end;

class function TAUIMemo.New(UI: IAUserInterface): IAUIclMemo;
begin
  Result := TAUIMemo.Create(UI, TMemo.Create(nil));
end;

procedure TAUIMemo.SetAllocateSize(Width, Height: Integer);
begin
  FControl.Height := Height;
  FControl.Width := Width;
end;

procedure TAUIMemo.SetPosition(ALeft, ATop: Integer);
begin
  FControl.Left := ALeft;
  FControl.Top := ATop;
end;

procedure TAUIMemo.SetFocus;
begin
  FControl.SetFocus();
end;

procedure TAUIMemo.SetRequestSize(Width, Height: Integer);
begin
  FRequestSize.Width := Width;
  FRequestSize.Height := Height;
end;

procedure TAUIMemo.SetName(const Value: AString);
begin
  FControl.Name := Value;
end;


function TAUIMemo.Get_Tag: Integer;
begin
      Result := FControl.Tag;
end;

procedure TAUIMemo.Set_Tag(Value: Integer);
begin
      FControl.Tag := Value;
end;

function TAUIMemo.Get_Left: Integer;
begin
      Result := FControl.Left;
end;

procedure TAUIMemo.Set_Left(Value: Integer);
begin
      FControl.Left := Value;
end;

function TAUIMemo.Get_Top: Integer;
begin
      Result := FControl.Top;
end;

procedure TAUIMemo.Set_Top(Value: Integer);
begin
      FControl.Top := Value;
end;

function TAUIMemo.Get_Width: Integer;
begin
      Result := FControl.Width;
end;

procedure TAUIMemo.Set_Width(Value: Integer);
begin
      FControl.Width := Value;
end;

function TAUIMemo.Get_Height: Integer;
begin
      Result := FControl.Height;
end;

procedure TAUIMemo.Set_Height(Value: Integer);
begin
      FControl.Height := Value;
end;

function TAUIMemo.Get_Cursor: Integer;
begin
      Result := FControl.Cursor;
end;

procedure TAUIMemo.Set_Cursor(Value: Integer);
begin
      FControl.Cursor := Value;
end;

function TAUIMemo.GetHint: AString;
begin
  Result := FControl.Hint;
end;

procedure TAUIMemo.SetHint(const Value: AString);
begin
  FControl.Hint := Value;
end;

function TAUIMemo.Get_HelpType: Integer;
begin
  Result := Integer(FControl.HelpType);
end;

procedure TAUIMemo.Set_HelpType(Value: Integer);
begin
  FControl.HelpType := THelpType(Value);
end;

function TAUIMemo.Get_HelpKeyword: AString;
begin
  Result := FControl.HelpKeyword;
end;

procedure TAUIMemo.Set_HelpKeyword(const Value: AString);
begin
  FControl.HelpKeyword := Value;
end;

function TAUIMemo.Get_HelpContext: Integer;
begin
      Result := FControl.HelpContext;
end;

procedure TAUIMemo.Set_HelpContext(Value: Integer);
begin
      FControl.HelpContext := Value;
end;

function TAUIMemo.Get_TabStop: ABoolean;
begin
  Result := FControl.TabStop;
end;

procedure TAUIMemo.Set_TabStop(Value: ABoolean);
begin
  FControl.TabStop := Value;
end;

function TAUIMemo.Get_Align: Integer;
begin
  Result := Integer(FControl.Align);
end;

procedure TAUIMemo.Set_Align(Value: Integer);
begin
  FControl.Align := TAlign(Value);
end;

function TAUIMemo.Get_Alignment: Integer;
begin
  Result := Integer(FControl.Alignment);
end;

procedure TAUIMemo.Set_Alignment(Value: Integer);
begin
  FControl.Alignment := TAlignment(Value);
end;

function TAUIMemo.Get_BevelInner: Integer;
begin
  {$IFNDEF UNIX}
  Result := Integer(FControl.BevelInner);
  {$ENDIF}
end;

procedure TAUIMemo.Set_BevelInner(Value: Integer);
begin
  {$IFNDEF UNIX}
  FControl.BevelInner := TBevelCut(Value);
  {$ENDIF}
end;

function TAUIMemo.Get_BevelKind: Integer;
begin
  {$IFNDEF UNIX}
  Result := Integer(FControl.BevelKind);
  {$ELSE}
  Result := 0;
  {$ENDIF}
end;

procedure TAUIMemo.Set_BevelKind(Value: Integer);
begin
  {$IFNDEF UNIX}
  FControl.BevelKind := TBevelKind(Value);
  {$ENDIF}
end;

function TAUIMemo.Get_BevelOuter: Integer;
begin
  {$IFNDEF UNIX}
  Result := Integer(FControl.BevelOuter);
  {$ELSE}
  Result := 0;
  {$ENDIF}
end;

procedure TAUIMemo.Set_BevelOuter(Value: Integer);
begin
  {$IFNDEF UNIX}
  FControl.BevelOuter := TBevelCut(Value);
  {$ENDIF}
end;

function TAUIMemo.Get_BiDiMode: Integer;
begin
  Result := Integer(FControl.BiDiMode);
end;

procedure TAUIMemo.Set_BiDiMode(Value: Integer);
begin
  FControl.BiDiMode := TBiDiMode(Value);
end;

function TAUIMemo.Get_BorderStyle: Integer;
begin
  Result := Integer(FControl.BorderStyle);
end;

procedure TAUIMemo.Set_BorderStyle(Value: Integer);
begin
  FControl.BorderStyle := TFormBorderStyle(Value);
end;

function TAUIMemo.Get_Color: Integer;
begin
  Result := FControl.Color;
end;

procedure TAUIMemo.Set_Color(Value: Integer);
begin
  FControl.Color := Value;
end;

{function TAUIMemo.Get_Ctl3D: Integer;
begin
    if (FControl.Ctl3D = False) then Result := 0;
    if (FControl.Ctl3D = True) then Result := 1;
end;}

{procedure TAUIMemo.Set_Ctl3D(Value: Integer);
begin
   if (Value = 0) then FControl.Ctl3D := False;
   if (Value = 1) then FControl.Ctl3D := True;
end;}

function TAUIMemo.Get_DragCursor: Integer;
begin
  Result := FControl.DragCursor;
end;

procedure TAUIMemo.Set_DragCursor(Value: Integer);
begin
  FControl.DragCursor := Value;
end;

function TAUIMemo.Get_DragKind: Integer;
begin
  {$IFNDEF UNIX}
    Result := Integer(FControl.DragKind);
  {$ELSE}
    Result := 0;
  {$ENDIF}
end;

procedure TAUIMemo.Set_DragKind(Value: Integer);
begin
  {$IFNDEF UNIX}
    FControl.DragKind := TDragKind(Value);
  {$ENDIF}
end;

function TAUIMemo.Get_DragMode: Integer;
begin
  Result := Integer(FControl.DragMode);
end;

procedure TAUIMemo.Set_DragMode(Value: Integer);
begin
  FControl.DragMode := TDragMode(Value);
end;

function TAUIMemo.GetEnabled: ABoolean;
begin
  Result := FControl.Enabled;
end;

procedure TAUIMemo.SetEnabled(Value: ABoolean);
begin
  FControl.Enabled := Value;
end;

function TAUIMemo.Get_Font: IAUIFont;
begin
  //Result := TExControlFont.Create(TFont(FControl.Font));
end;

function TAUIMemo.Get_HideSelection: ABoolean;
begin
  {$IFNDEF UNIX}
    Result := FControl.HideSelection;
  {$ELSE}
    Result := False;
  {$ENDIF}
end;

procedure TAUIMemo.Set_HideSelection(Value: ABoolean);
begin
  {$IFNDEF UNIX}
    FControl.HideSelection := Value;
  {$ENDIF}
end;

function TAUIMemo.Get_ImeMode: Integer;
begin
  {$IFNDEF UNIX}
  Result := Integer(FControl.ImeMode);
  {$ELSE}
  Result := 0;
  {$ENDIF}
end;

procedure TAUIMemo.Set_ImeMode(Value: Integer);
begin
  {$IFNDEF UNIX}
  FControl.ImeMode := TImeMode(Value);
  {$ENDIF}
end;

function TAUIMemo.Get_ImeName: AString;
begin
  {$IFNDEF UNIX}
  Result := FControl.ImeName;
  {$ENDIF}
end;

procedure TAUIMemo.Set_ImeName(const Value: AString);
begin
  {$IFNDEF UNIX}
  FControl.ImeName := Value;
  {$ENDIF}
end;

function TAUIMemo.Get_LinesCount: Integer;
begin
  Result := FControl.Lines.Count;
end;

function TAUIMemo.Get_Lines(Index: Integer): AString;
begin
  if ((Index >= 0) and (Index < FControl.Lines.Count)) then
    Result := FControl.Lines[Index]
  else
    Result := '';
end;

procedure TAUIMemo.Set_Lines(Index: integer; const Value: AString);
begin
  if ((Index >= 0) and (Index < FControl.Lines.Count)) then
    FControl.Lines[Index] := Value;
end;

function TAUIMemo.Get_MaxLength: Integer;
begin
  Result := FControl.MaxLength;
end;

procedure TAUIMemo.Set_MaxLength(Value: Integer);
begin
  FControl.MaxLength := Value;
end;

{function TAUIMemo.Get_OEMConvert: Integer;
begin
  if (FControl.OEMConvert = False) then Result := 0;
  if (FControl.OEMConvert = True) then Result := 1;
end;}

{procedure TAUIMemo.Set_OEMConvert(Value: Integer);
begin
  if (Value = 0) then FControl.OEMConvert := False;
  if (Value = 1) then FControl.OEMConvert := True;
end;}

{function TAUIMemo.Get_ParentBiDiMode: Integer;
begin
  Result := Integer(FControl.ParentBiDiMode);
  if (FControl.ParentBiDiMode = True) then Result := 1;
end;

procedure TAUIMemo.Set_ParentBiDiMode(Value: Integer);
begin
   if (Value = 0) then FControl.ParentBiDiMode := False;
   if (Value = 1) then FControl.ParentBiDiMode := True;
end;}

{function TAUIMemo.Get_ParentColor: Integer;
begin
    if (FControl.ParentColor = False) then Result := 0;
    if (FControl.ParentColor = True) then Result := 1;
end;}

{procedure TAUIMemo.Set_ParentColor(Value: Integer);
begin
   if (Value = 0) then FControl.ParentColor := False;
   if (Value = 1) then FControl.ParentColor := True;
end;}

{function TAUIMemo.Get_ParentCtl3D: Integer;
begin
    if (FControl.ParentCtl3D = False) then Result := 0;
    if (FControl.ParentCtl3D = True) then Result := 1;
end;

procedure TAUIMemo.Set_ParentCtl3D(Value: Integer);
begin
   if (Value = 0) then FControl.ParentCtl3D := False;
   if (Value = 1) then FControl.ParentCtl3D := True;
end;}

{function TAUIMemo.Get_ParentFont: Integer;
begin
    if (FControl.ParentFont = False) then Result := 0;
    if (FControl.ParentFont = True) then Result := 1;
end;

procedure TAUIMemo.Set_ParentFont(Value: Integer);
begin
   if (Value = 0) then FControl.ParentFont := False;
   if (Value = 1) then FControl.ParentFont := True;
end;}

{function TAUIMemo.Get_ParentShowHint: Integer;
begin
    if (FControl.ParentShowHint = False) then Result := 0;
    if (FControl.ParentShowHint = True) then Result := 1;
end;}

{procedure TAUIMemo.Set_ParentShowHint(Value: Integer);
begin
   if (Value = 0) then FControl.ParentShowHint := False;
   if (Value = 1) then FControl.ParentShowHint := True;
end;}

function TAUIMemo.Get_PopupMenu: IAUIPopupMenu;
begin
  //Result := TExControlPopupMenu.Create(TTntPopupMenu(FControl.PopupMenu));
end;

function TAUIMemo.Get_ReadOnly: ABoolean;
begin
  Result := FControl.ReadOnly;
end;

procedure TAUIMemo.Set_ReadOnly(Value: ABoolean);
begin
  FControl.ReadOnly := Value;
end;

function TAUIMemo.Get_ScrollBars: Integer;
begin
  Result := Integer(FControl.ScrollBars);
end;

procedure TAUIMemo.Set_ScrollBars(Value: Integer);
begin
  FControl.ScrollBars := TScrollStyle(Value);
end;

{function TAUIMemo.Get_ShowHint: Integer;
begin
    if (FControl.ShowHint = False) then Result := 0;
    if (FControl.ShowHint = True) then Result := 1;
end;

procedure TAUIMemo.Set_ShowHint(Value: Integer);
begin
   if (Value = 0) then FControl.ShowHint := False;
   if (Value = 1) then FControl.ShowHint := True;
end;}

function TAUIMemo.Get_TabOrder: Integer;
begin
  Result := FControl.TabOrder;
end;

procedure TAUIMemo.Set_TabOrder(Value: Integer);
begin
  FControl.TabOrder := Value;
end;

function TAUIMemo.GetVisible: ABoolean;
begin
  Result := FControl.Visible;
end;

procedure TAUIMemo.SetVisible(Value: ABoolean);
begin
  FControl.Visible := Value;
end;

function TAUIMemo.Get_WantReturns: ABoolean;
begin
  Result := FControl.WantReturns;
end;

procedure TAUIMemo.Set_WantReturns(Value: ABoolean);
begin
  FControl.WantReturns := Value;
end;

function TAUIMemo.Get_WantTabs: ABoolean;
begin
  Result := FControl.WantTabs;
end;

procedure TAUIMemo.Set_WantTabs(Value: ABoolean);
begin
  FControl.WantTabs := Value;
end;

function TAUIMemo.Get_WordWrap: ABoolean;
begin
  Result := FControl.WordWrap;
end;

procedure TAUIMemo.Set_WordWrap(Value: ABoolean);
begin
  FControl.WordWrap := Value;
end;

function TAUIMemo.GetText: AString;
begin
  Result := FControl.Text;
end;

procedure TAUIMemo.SetText(const Value: AString);
begin
  FControl.Text := Value;
end;

end.
